package com.gilgamesh.mall.product.dao;

import com.gilgamesh.mall.product.sql.StockSql;
import com.gilgamesh.mall.sdk.bean.product.StockEntity;
import com.gilgamesh.mall.sdk.dto.product.StockDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * Created by Peiyao.Wang on 2021/1/14
 *
 * @author Peiyao.Wang
 * @date 2021/1/13
 */
@Mapper
public interface StockDao {
    @Results(
            id = "stockDTOMap",value = {
            @Result(column = "id" ,jdbcType = JdbcType.BIGINT,javaType = Long.class,property = "id"),
            @Result(column = "sku_code",jdbcType = JdbcType.VARCHAR,javaType = String.class,property = "skuCode"),
            @Result(column = "remaining_quantity",jdbcType = JdbcType.INTEGER,javaType =java.lang.Integer.class,property = "remainingQuantity"),
     }
    )

    @SelectProvider(type = StockSql.class , method = "listStocks")
    List<StockDTO> listStocks(StockEntity stockEntity);

    @Select("select * from t_stock where id =#{id}")
    StockDTO getStockById(Long id);

}
